#pragma once

#include <functional>
#include <utility>
#include <workflow/Workflow.h>
#include <protocol/frpc_msgio.h>
#include <workflow/WFServer.h>
#include <workflow/WFTaskFactory.h>
#include <workflow/WFConnection.h>
#include <task/frpc_task.h>
#include <handler/handlers.h>
namespace Frpc
{

	static constexpr struct WFServerParams FRPC_ARGS =
		{
			/*	.max_connections		=	*/ 2000,
			/*	.peer_response_timeout	=	*/ 10 * 1000,
			/*	.receive_timeout		=	*/ -1,
			/*	.keep_alive_timeout		=	*/ 1800 * 1000,
			/*	.request_size_limit		=	*/ (size_t)-1,
			/*	.ssl_accept_timeout		=	*/ 10 * 1000
			};

	class Server : public WFServer<RequestMsg, ReplyMsg>
	{
	static	void task_handler(WFNetworkTask<RequestMsg, ReplyMsg> *task);

	protected:
		static Router _router;


		virtual WFConnection *new_connection(int accept_fd);
		virtual CommSession *new_session(long long seq, CommConnection *conn);

	public:
		Server(Router &&router) :WFServer(&FRPC_ARGS, Server::task_handler) {
			_router=router;
		}
	};
}